<template>
  <div class="table-main">
    <el-dialog
      :close-on-click-modal="false"
      @close="handMyClose"
      :append-to-body="true"
      title="派车单"
      :visible.sync="dialogVisible1"
      width="60%"
    >
      <div style="margin-top:50px;">
        <el-form ref="form" :model="form" label-width="120px" :rules="rules">
          <el-row :gutter="20" justify="center" type="flex">
            <el-col :span="16">
              <el-form-item label="司机姓名:">
                <el-input :disabled="isShow==3" v-model="form.driverName " placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20" justify="center" type="flex">
            <el-col :span="16">
              <el-form-item label="司机电话:">
                <el-input :disabled="isShow==3" v-model="form.driverPhone " placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20" justify="center" type="flex">
            <el-col :span="16">
              <el-form-item label="公交车牌号:">
                <el-input :disabled="isShow==3" v-model="form.orderNum " placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="handNo()">取 消</el-button>
        <el-button
          type="primary"
          @click="handFromSub('form')"
          :loading="bntLoading"
          v-if="isShow != 3"
        >确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { imgSizi } from '@/utils/myUtils'
export default {
  name: 'SidebarLogo',
  components: {},

  watch: {
    isState(newObj) {
      this.isShow = newObj
    }
  },
  computed: {
    totalNum() {
      let realVal = parseFloat(this.form.moeny1)
      let realVal2 = parseFloat(this.form.moeny2)
      let num = realVal + realVal2
      return parseFloat(num).toFixed(2)
    }
  },
  props: {
    isState: {
      type: Number,
      default: 0
    }
  },
  data() {
    var validatePass3 = (rule, value, callback) => {
      console.log(md5(value), '!==', this.passMd5)
      if (value == '') {
        callback(new Error('请输入原密码'))
      } else if (md5(value) != this.passMd5) {
        callback(new Error('原密码和输入的不一致!'))
      } else {
        callback()
      }
    }
    var validatePass2 = (rule, value, callback) => {
      if (value == '') {
        callback(new Error('请再次输入密码'))
      } else if (value != this.form.passWord) {
        callback(new Error('两次输入密码不一致!'))
      } else {
        callback()
      }
    }
    return {
      orderStaList: [
        {
          value: 1,
          label: '待确定'
        },
        {
          value: 2,
          label: '待付款'
        },
        {
          value: 3,
          label: '进行中'
        },
        {
          value: 4,
          label: '已完成'
        }
      ],
      orderStaList2: [
        {
          value: 1,
          label: '已支付'
        },
        {
          value: 2,
          label: '未支付'
        }
      ],
      passwordType2: 'password',
      capsTooltip2: false,
      passwordType3: 'password',
      capsTooltip3: false,
      bntLoading: false,
      loading2: false,
      rules: {
        checkPass: [
          { required: true, validator: validatePass2, trigger: 'blur' }
        ],
        oldPassWord: [
          { required: true, validator: validatePass3, trigger: 'blur' }
        ],
        companyName: [
          { required: true, message: '请输入单位名称', trigger: 'blur' }
        ],
        passWord: [{ required: true, message: '请输入密码', trigger: 'blur' }],
        userName: [
          { required: true, message: '请输入账户名称', trigger: 'blur' },
          {
            validator(rule, value, callback) {
              var reg = /^[A-Za-z0-9]+$/
              if (reg.test(value)) {
                callback()
              } else {
                callback(new Error('请输入正确用户名称！'))
              }
            },
            trigger: 'blur'
          }
        ],
        email: [
          { required: true, message: '请输入邮箱' },
          {
            validator(rule, value, callback) {
              var reg = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
              if (reg.test(value)) {
                callback()
              } else {
                callback(new Error('请输入正确的邮箱！'))
              }
            },
            trigger: 'blur'
          }
        ],
        phone: [
          { required: true, message: '请输入手机号' },
          {
            validator(rule, value, callback) {
              var reg = /^(?:(?:\+|00)86)?1[3-9]\d{9}$/
              if (reg.test(value)) {
                callback()
              } else {
                callback(new Error('请输入正确的手机号！'))
              }
            },
            trigger: 'blur'
          }
        ]
      },
      headers: {
        token: localStorage.getItem('mytoken') || ''
      },
      bannerType: [
        {
          label: '汽车轮播图',
          value: 2
        },
        {
          label: '商品轮播图',
          value: 1
        },
        {
          label: '首页弹窗广告',
          value: 3
        }
      ],
      form: {},
      shopStatusOptions: [],
      isShow: 0,
      imageUrl: '',
      dialogImageUrl: '',
      dialogVisible1: false,
      addressKeyword: '',
      activeName: 'first',
      dialogVisible: false,
      tipShow: false
    }
  },
  async mounted() {},
  methods: {
    handNo() {
      this.dialogVisible1 = false
    },
    checkCapslock2(e) {
      const { key } = e
      this.capsTooltip2 = key && key.length === 1 && key >= 'A' && key <= 'Z'
    },
    checkCapslock3(e) {
      const { key } = e
      this.capsTooltip3 = key && key.length === 1 && key >= 'A' && key <= 'Z'
    },
    showPwd3() {
      if (this.passwordType3 === 'password') {
        this.passwordType3 = ''
      } else {
        this.passwordType3 = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password3.focus()
      })
    },
    showPwd2() {
      if (this.passwordType2 === 'password') {
        this.passwordType2 = ''
      } else {
        this.passwordType2 = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password2.focus()
      })
    },
    uploadChange() {},
    onError() {},
    handGetShop(id) {
      this.$api.selectSendCarByIdSendCar({ id }).then(res => {
        this.form = res.data.data
      })
    },
    handMyClose() {
      this.$refs.form.resetFields()
      // this.$parent.closeFrom()
      for (let key in this.form) {
        this.form[key] = ''
      }
    },
    handFromSub(formName) {
      //1编辑
      if (this.isState == 1) {
        this.$refs[formName].validate(valid => {
          if (valid) {
            this.bntLoading = true
            this.$api
              .editSendCar(this.form)
              .then(res => {
                this.dialogVisible1 = false
                this.$parent.init()
                console.log(res, '编辑', this.form)
                this.$message({
                  message: res.data.message,
                  type: 'success'
                })
                this.bntLoading = false
              })
              .finally(() => {
                this.bntLoading = false
              })
          } else {
            console.log('error submit!!')
            this.$message({
              message: '请完成表单录入'
            })
            this.bntLoading = false
            return false
          }
        })
      } else if (this.isState == 0) {
        this.$refs[formName].validate(valid => {
          if (valid) {
            this.bntLoading = true
            this.$api
              .getShopBannerAdd(this.form)
              .then(res => {
                this.dialogVisible1 = false
                this.bntLoading = false
                this.$parent.init()
                this.$refs.form.resetFields()
                console.log(res, '添加轮播,表单验证', this.form)
                this.$message({
                  message: res.data.message,
                  type: 'success'
                })
              })
              .finally(() => {
                this.bntLoading = false
              })
          } else {
            console.log('error submit!!')
            this.$message({
              message: '请完成表单录入'
            })
            return false
          }
        })
      }
    },

    // handSuccess(response, file, fileList) {
    //   console.log(response, file, fileList, '成功回调')
    //   this.form.shopImg = response.message
    // },
    handleRemove(file, fileList) {
      console.log(file, fileList)
    },
    // handlePictureCardPreview(file) {
    //   this.dialogImageUrl = file.url
    //   this.dialogVisible2 = true
    // },
    handleClose() {
      this.dialogVisible = false
    },
    handMapShow() {
      this.dialogVisible = true
    },
    handleClick() {}
  }
}
</script>

<style lang="scss" scoped>
.map_btn {
  width: 82px;
  height: 22px;
  background: rgba(56, 173, 147, 1);
  border-radius: 4px;
  color: #fff;
  font-size: 14px;
  line-height: 22px;
  text-align: center;
  margin-top: 8px;
}
/deep/ .el-form-item__label {
  font-size: 14px;
  color: #000;
  font-weight: bold;
}
.form_box {
  width: 80%;
  margin: 0 auto;
}
.avatar-uploader /deep/ .el-upload {
  border: 1px dashed #38ad93;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #38ad93;
  width: 336px;
  height: 90px;
  line-height: 90px;
  text-align: center;
}
.avatar {
  width: 336px;
  height: 90px;
  display: block;
}
</style>
